<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PersonaController
 *
 * @author dliebel
 */
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Db\Adapter\Adapter;
use Application\Model\Persona;


class PersonaController extends AbstractActionController {

    //put your code here
    public $dbAdapter;

    public function indexAction() {
        if ($this->getRequest()->isPost()) {
            $this->dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter');
            $u = new Persona($this->dbAdapter);
            //echo "se recibió el post";exit;
            $data = $this->request->getPost();
            $u->addUsuario($data);
            return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/application/formulario/registro/1');
            /*
              $form=new Formularios("form");
              $valores=array
              (
              "titulo"=>"Registro de Usuario",
              "form"=>$form,
              'url'=>$this->getRequest()->getBaseUrl(),
              'respuesta'=>'Registro ingresado exitosamente'
              );
              return new ViewModel($valores);
             */
        } else {
            //zona del formulario
            $form = new Formularios("form");
            $id = (int) $this->params()->fromRoute('id', 0);
            $valores = array
                (
                "titulo" => "Registro de Usuario",
                "form" => $form,
                'url' => $this->getRequest()->getBaseUrl(),
                'id' => $id
            );
            return new ViewModel($valores);
        }
    }

}

